package com.mengniu.commerce.admin.api.factory;

import com.mengniu.commerce.admin.api.RemoteStoreService;
import com.mengniu.commerce.admin.api.domain.SysStore;
import com.mengniu.commerce.common.core.domain.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 店铺服务降级处理
 *
 * @author yz_sm
 */
@Component
public class RemoteStoreFallbackFactory implements FallbackFactory<RemoteStoreService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteStoreFallbackFactory.class);

    @Override
    public RemoteStoreService create(Throwable throwable)
    {
        log.error("店铺服务调用失败:{}", throwable.getMessage());
        return new RemoteStoreService()
        {
            @Override
            public R<SysStore> getStoreInfo(String code, String source)
            {
                return R.fail("获取店铺失败:" + throwable.getMessage());
            }
        };
    }
}
